﻿using Domain.Event;
using Domain.IRepositorys;
using Domain.Model;
using Domain.Services;
using Domain.Types;
using Infrastructure.DomainEvent;
using Infrastructure.Error;
using Infrastructure.UniOfWorkBase;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OtherLib.AliPay;
using OtherLib.Getui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Utility;

namespace Application.Event
{
    /// <summary>
    /// 用户提现事件
    /// </summary>
    public class PushMsgEventHandler : IDomainEventHandler<PushMsgEvent>
    {
        public IWalletRepository walletRepository { get; set; }
        public IUserRepository userRepository { get; set; }
        public IWithDrawRepository withDrawRepository { get; set; }
        public MsgPulishService msgPulishService { get; set; }
        public IEFUnitOfWork efUnitOfWork { get; set; }
        public WalletService walletService { get; set; }
        public IGeTuiRelationRepository geTuiRelationRepository { get; set; }
        public ILogger<WithDrawEventHandler> _logger { get; set; }
        public override Task HandleAysnc(PushMsgEvent domainEvent, CancellationToken cancellationToken = default)
        {            
            var gt = geTuiRelationRepository.Entities.FirstOrDefault(i => i.UserID == domainEvent.UserID);
            //if (gt == null) throw new BizException("该用户未绑定个推");
            if (gt == null) return Task.CompletedTask;
            GetuiUtil.SendMsgNotify(domainEvent.Title, domainEvent.Message, domainEvent.MsgData, gt.GeTuiID);

            return Task.CompletedTask;
        }
    }
}
